<?php
/**
 * tpshop
 * ============================================================================
 * * 版权所有 2015-2027 深圳搜豹网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.tp-shop.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * 2015-11-21
 */
namespace Mobile\Controller;

use Home\Logic\UsersLogic;
use Think\Page;
use Think\Verify;
use Think\AjaxPage;

class AdminController extends MobileBaseController
{

    public function index(){
      $user=session();
      $todaytime=strtotime("today");
      $day=date("Y-m-d",strtotime("-1 day"));
      $zuokai=strtotime($day);
      $zuojie=$zuokai+86399;  
       $where=array();
       if($user['admin']||$user['user']){
      if($user['admin']){
       $roleid=$user['admin']['role_id'];
        $nickname=$user['admin']['user_name'];
        $order=M('order')->field('count(*) as order_shu')->where("add_time>=$todaytime and roleid=$roleid")->find();
        $total_amount_in = M('order')->where("add_time>=$todaytime and pay_status=1 and order_status in(1,2,4) and roleid=$roleid")->sum('order_amount');
        $total_amount_out = M('order')->where("add_time>=$todaytime and pay_status=1 and order_status =6 and roleid=$roleid")->sum('yajin');
        $order_goods=M('order')->join("ty_order_goods on ty_order.order_id=ty_order_goods.order_id")->where("add_time>=$todaytime and order_status in (1,2,4,6) and pay_status=1 and ty_order.roleid=$roleid")->sum('ty_order_goods.goods_num');
        $order1=M('order')->field('count(*) as order_shu')->where("add_time>=$zuokai and add_time <=$zuojie and roleid=$roleid")->find();
        $total_amount_in1 = M('order')->where("add_time>=$zuokai and add_time <=$zuojie and pay_status=1 and order_status in(1,2,4) and roleid=$roleid")->sum('order_amount');
        $total_amount_out1 = M('order')->where("add_time>=$zuokai and add_time <=$zuojie and pay_status=1 and order_status =6 and roleid=$roleid")->sum('yajin');
      }
      if($user['user']){
        
        $nickname=$user['user']['nickname'];
        $store_id=$user['user']['seller_id'];
        $store=M('store')->where("store_id=$store_id")->find();
        $group_id=$user['user']['group_id'];
        
        $tuixiao_id=$user['user']['user_id'];
        if($group_id=='6' ||($group_id=='9'||$group_id=='10'&& $store_id>'0')){

            
            $total_amount_in = M('order')->where("store_id = ".$store_id." and add_time>=$todaytime and pay_status=1 and order_status in(1,2,4) ")->sum('order_amount');
            $total_amount_out = M('order')->where("store_id = ".$store_id." and add_time>=$todaytime and pay_status=1 and order_status =6 ")->sum('yajin');
             $order=M('order')->field('count(*) as order_shu')->where(" store_id = ".$store_id." and add_time>=$todaytime ")->find();

             $order_goods=M('order')->join("ty_order_goods on ty_order.order_id=ty_order_goods.order_id")->where("add_time>=$todaytime and order_status in (1,2,4,6) and pay_status=1  and ty_order.store_id = ".$store_id."")->sum('ty_order_goods.goods_num');
            
             $order1=M('order')->field('count(*) as order_shu')->where(" store_id = ".$store_id." and add_time>=$zuokai and add_time <=$zuojie ")->find();

             $total_amount_in1 = M('order')->where("store_id = ".$store_id." and add_time>=$zuokai and add_time <=$zuojie and pay_status=1 and order_status in(1,2,4) ")->sum('order_amount');

            $total_amount_out1 = M('order')->where("store_id = ".$store_id." and add_time>=$zuokai and add_time <=$zuojie and pay_status=1 and order_status =6 ")->sum('yajin');

        }elseif($group_id=='5'||$group_id=='7'){

          $total_amount_in = M('order')->where("store_id = ".$store_id." and add_time>=$todaytime and pay_status=1 and order_status in(1,2,4)")->sum('order_amount');
          $total_amount_out = M('order')->where("store_id = ".$store_id." and add_time>=$todaytime and pay_status=1 and order_status =6")->sum('yajin');
          $order=M('order')->field('count(*) as order_shu')->where(" store_id = ".$store_id." and add_time>=$todaytime ")->find();
         $order_goods=M('order')->join("ty_order_goods on ty_order.order_id=ty_order_goods.order_id")->where("add_time>=$todaytime and order_status in (1,2,4,6) and pay_status=1  and ty_order.store_id = ".$store_id." ")->sum('ty_order_goods.goods_num');
          $total_amount_in1 = M('order')->where("store_id = ".$store_id." and add_time>=$zuokai and add_time <=$zuojie and pay_status=1 and order_status in(1,2,4)")->sum('order_amount');
          $total_amount_out1 = M('order')->where("store_id = ".$store_id." and add_time>=$zuokai and add_time <=$zuojie and pay_status=1 and order_status =6")->sum('yajin');
           $order1=M('order')->field('count(*) as order_shu')->where(" store_id = ".$store_id." and add_time>=$zuokai and add_time <=$zuojie ")->find();
        }elseif(($group_id=='9'||$group_id=='10')&& $store_id='0'){
            
          $nickname=$user['user']['nickname'];
          $order=M('order')->field('count(*) as order_shu')->where("add_time>=$todaytime")->find();
          
          $total_amount_in = M('order')->where("add_time>=$todaytime and pay_status=1 and order_status in(1,2,4)")->sum('order_amount');
          $total_amount_out = M('order')->where("add_time>=$todaytime and pay_status=1 and order_status =6")->sum('yajin');
          $order_goods=M('order')->join("ty_order_goods on ty_order.order_id=ty_order_goods.order_id")->where("add_time>=$todaytime and order_status in (1,2,4,6) and pay_status=1 ")->sum('ty_order_goods.goods_num');
          $order1=M('order')->field('count(*) as order_shu')->where("add_time>=$zuokai and add_time <=$zuojie")->find();
          $total_amount_in1 = M('order')->where("add_time>=$zuokai and add_time <=$zuojie and pay_status=1 and order_status in(1,2,4)")->sum('order_amount');
          $total_amount_out1 = M('order')->where("add_time>=$zuokai and add_time <=$zuojie and pay_status=1 and order_status =6")->sum('yajin');
        }
        $condition['seller_id']=$store_id;
      }
      }else{
         header("Location:" . U('Mobile/Admin/login'));
      }
      $condition['reg_time']=array('egt',$todaytime);
      $renshu=M('users')->field("count(*) as renshu ")->where($condition)->find();
      $xiaoshou=$total_amount_in+$total_amount_out;
      $xiaoshou1=$total_amount_in1+$total_amount_out1;
      $this->assign('order_goods',$order_goods);
      $this->assign('xiaoshou1',$xiaoshou1);
      $this->assign('order1',$order1);
      $this->assign('order',$order);
      $this->assign('xiaoshou',$xiaoshou);
      $this->assign('renshu',$renshu);
      $this->assign('store',$store);
      $this->assign('nickname',$nickname);
      $this->display();
    }

    public function admin_list(){
     
      $timegap=$_REQUEST['timegap'];
      $timegap1=$_REQUEST['timegap1'];
      if($timegap){
        $begin =strtotime($timegap);
        $end = strtotime($timegap1)+86399;
      }else{
        $begin1 = date('Y-m-d');//30天前
        $begin = strtotime($begin1);
        $end =time();
      }
      
      $user=session();
      
      if($user['admin']['admin_id']>'0' or $user['user']['user_id']>'0'){
        $admin=$user['admin']['admin_id'];
        $seller=$user['user']['user_id'];
       
        if($admin >'0' || ($user['user']['group_id']=='9'||$user['user']['group_id']=='10' &&$user['user']['seller_id']=='0')){
         
            $role_id=$user['admin']['role_id'];
            if($role_id==''){
              $role_id=$user['user']['roleid'];
            }
            $nickname=$user['admin']['user_name'];
            if($nickname==''){
              $nickname=$user['user']['nickname'];
            }
            $store=M('store')->field('store_id,store_name')->where("roleid=$role_id")->select();
            foreach ($store as $key =>$value) {
              $store_id=$value['store_id'];
              $order_detail = M('order')->field('user_id,consignee,tuiguangid,doctor_id,total_amount,yajin,order_id,pay_code,add_time')
              ->where("store_id = $store_id and add_time >=$begin and add_time <=$end  and order_status in(1,2,4,6) and tuiguangid !=0")
              ->select();
              $classnum = 0;
              $class_total_fee = 0;
              $class_total_yajin = 0;
              $class_total_qk = 0;
              foreach ($order_detail as $ke => $va) {
                $order_goods_detail = M('order_goods')->field('goods_id,goods_num,goods_name')
                ->where("order_id = ".$va['order_id']."")->find();
                $classnum += $order_goods_detail['goods_num'];
                $class_total_fee +=  $va['total_amount'];
                if($va['yajin'] != "0.00") {
                  $class_total_qk += $va['total_amount']-$va['yajin'];
                  $class_total_yajin += $va['yajin'];
                }else{
                  $class_total_qk +=0;
                  $class_total_yajin += $va['total_amount'];
                }
              }
              $order_count_detail[$key] = array(
                'store_id'=>$store_id,
                'store_name'=>$value['store_name'],
                'classnum' => $classnum,
                'class_total_fee' => $class_total_fee,
                'class_total_yajin' => $class_total_yajin,
                'class_total_qk' => $class_total_qk,
              );

              $total_fee += $class_total_fee;
              $total_num += $classnum;
              $total_yajin += $class_total_yajin;
              $total_qk += $class_total_qk;
            }
           
            $total_list = array(
              'total_num' => $total_num,
              'total_fee' => $total_fee,
              'total_yajin' => $total_yajin,
              'total_qk' => $total_qk,
            );
            $this->assign('total_list',$total_list);
            $this->assign('order_count_detail',$order_count_detail);
            $this->assign('timegap',$timegap);
            $this->assign('timegap1',$timegap1);
            $this->assign('nickname',$nickname);
            $this->display();
        }else{

          $nickname=$user['user']['nickname'];
          $store=M('seller')->field('store_id,group_id,seller_id')->where("user_id=$seller and is_admin=0")->find();
          $store_id=$store['store_id'];
          $group_id=$store['group_id'];
          $seller_id=$store['seller_id'];
          if($group_id=='6'){
            $seller=M('seller')->field('user_id,group_id')->where("store_id=$store_id and is_admin=0 ")->select();
          }
          if($group_id=='7'){
            $seller=M('seller')->field('user_id,group_id')->where("(seller_id=$seller_id or shangji_id =$seller_id )and is_admin=0  ")->select();
          }
          if($group_id=='5'){
            $seller=M('seller')->field('user_id,group_id')->where("seller_id=$seller_id and is_admin=0")->select();

          }
          if($group_id=='9'||$group_id=='10'){
            $seller=M('seller')->field('user_id,group_id')->where("store_id=$store_id and is_admin=0 and group_id in(5,6,7)")->select();
          }
          $class = M('goods_category')->field('id,name')->where("level=3")->select();
          $class_id = array();
          $class_name = array();
          foreach ($class as $key => $v) {
            $class_id[] = $v['id'];
            $class_name[$v['id']] = $v['name'];
          }
          $class_id = implode(',', $class_id);
          $class_goods = M('goods')->field('goods_id,cat_id3,goods_name')->where("cat_id3 in ($class_id)")->select();
          $class_goods_f = array();
          //获取分类的商品id
          foreach($class_goods as $v)
          {
            $class_goods_f[$v['cat_id3']][] = $v['goods_id'];
          }
          $order_count_detail = array();
          foreach($seller as $key =>$val){
            $tuiguangid=$val['user_id'];

            $order_detail = M('order')->field('total_amount,yajin,order_id')
            ->where("store_id = $store_id and add_time >=$begin and add_time <=$end  and order_status in(1,2,4,6) and tuiguangid=$tuiguangid")
            ->select();
            $user_name=M('users')->field('nickname')->where("user_id=$tuiguangid")->find();
            $username=$user_name['nickname'];
            $group_id=$val['group_id'];
            
              $classnum = 0;
              $class_total_fee = 0;
              $class_total_yajin = 0;
              $class_total_qk = 0;
              foreach ($order_detail as $ke => $va) {
                $order_goods_detail = M('order_goods')->field('goods_id,goods_num,goods_name')
                ->where("order_id = ".$va['order_id']."")->find();
                $classnum += $order_goods_detail['goods_num'];
                $class_total_fee +=  $va['total_amount'];
                if($va['yajin'] != "0.00") {
                  $class_total_qk += $va['total_amount']-$va['yajin'];
                  $class_total_yajin += $va['yajin'];
                }else{
                  $class_total_qk +=0;
                  $class_total_yajin += $va['total_amount'];
                }
              }
               $order_count_detail[$key] = array(
                'group_id'=>$group_id,
                'user_id'=>$tuiguangid,
                'user_name'=>$username,
                'classnum' => $classnum,
                'class_total_fee' => $class_total_fee,
                'class_total_yajin' => $class_total_yajin,
                'class_total_qk' => $class_total_qk,
              );
               $total_fee += $class_total_fee;
              $total_num += $classnum;
              $total_yajin += $class_total_yajin;
              $total_qk += $class_total_qk;
              }
          $total_list = array(
          'total_num' => $total_num,
          'total_fee' => $total_fee,
          'total_yajin' => $total_yajin,
          'total_qk' => $total_qk,
          );
          $this->assign('total_list',$total_list);
          $this->assign('order_count_detail',$order_count_detail);
          $this->assign('timegap',$timegap);
          $this->assign('timegap1',$timegap1);
          $this->display('jl');
          $this->assign('nickname',$nickname);

        }        
      }
    }

    public function logout()
    {
        session_unset();
        session_destroy();
        setcookie('cn', '', time() - 3600, '/');
        setcookie('user_id', '', time() - 3600, '/');
        header("Location:" . U('Mobile/Admin/login'));
    }
    /**
     *  登录
     */
    public function login()
    {   
      $user=session();
        if ($user['user']['user_id'] > 0) {
            header("Location: " . U('Mobile/Admin/index'));
        }
        $referurl = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : U("Mobile/Admin/index");
        $this->assign('referurl', $referurl);
        $this->display();
    }

    public function do_login()
    {
        $username = I('post.username');
        $password = I('post.password');
       	if(is_numeric($username)){
       		$logic = new UsersLogic();
        	$res = $logic->login($username, $password);
       	}else{
       		$user=M('Admin')->where(array('user_name'=>$username,'password'=>encrypt($password )))->find();
       		$res = array();
       	 	if(!$user){
              $res = array('status'=>-1,'msg'=>'账号密码错误!');
        	}else{
           		$res = array('status'=>2,'msg'=>'登陆成功','result'=>$user);
            }
       	}
       	if($res['status']=='1'){
       		$res['url'] = urldecode('index');
          session('user',$res['result']);
          $user = session('user');
          $user = M('users')->where("user_id = {$user['user_id']}")->find();
          $seller = M('seller')->where("user_id = {$user['user_id']}")->find();
          session('user', $user);  //覆盖session 中的 user
          session('seller', $seller);  //覆盖session 中的 user
       	}elseif($res['status']=='2'){
          $res['status']='1';
          $res['url'] = urldecode('index');
          session('admin',$res['result']);

        }
       	exit(json_encode($res));
    }

    Public function store(){
      $timegap=$_REQUEST['timegap'];
      $timegap1=$_REQUEST['timegap1'];
      if($timegap){
        $begin =strtotime($timegap);
        $end = strtotime($timegap1)+86399;
      }else{
        $begin1 = date('Y-m-d');//30天前
        $begin = strtotime($begin1);
        $end =time();
      }
      $user=session();
      $nickname=$user['admin']['user_name'];
      if($nickname==''){
        $nickname=$user['user']['nickname'];
      }
      $store_id=$_GET['store_id'];
      $storeinfo = M('store')->field('store_name')->where("store_id=$store_id")->find();
      $class = M('goods_category')->field('id,name')->where("level=3")->select();
      $class_id = array();
      $class_name = array();
      foreach ($class as $key => $v) {
        $class_id[] = $v['id'];
        $class_name[$v['id']] = $v['name'];
      }
      $class_id = implode(',', $class_id);
      $class_goods = M('goods')->field('goods_id,cat_id3,goods_name')->where("cat_id3 in ($class_id)")->select();
    
      $class_goods_f = array();
      //获取分类的商品id
      foreach($class_goods as $v)
      {
        $class_goods_f[$v['cat_id3']][] = $v['goods_id'];
      }
      //根据分类的商品id查询总金额欠款等
      $order_detail = M('order')->field('user_id,consignee,tuiguangid,doctor_id,total_amount,yajin,order_id,pay_code,add_time')
      ->where("store_id = $store_id and add_time >=$begin and add_time <=$end  and order_status in(1,2,4,6) and tuiguangid !=0")
      ->select();
      $order_count_detail = array();

      foreach ($class_goods_f as $key => $v) {
        $vn = implode(',', $v);

        $classnum = 0;
        $class_total_fee = 0;
        $class_total_yajin = 0;
        $class_total_qk = 0;
        foreach ($order_detail as $ke => $va) {
          $order_goods_detail = M('order_goods')->field('goods_id,goods_num,goods_name,goods_price')
          ->where("order_id = ".$va['order_id']." and goods_id in($vn)")->find();
          $classname = $class_name[$key];
          if (!$order_goods_detail) {
            continue;
          }
          
          $classnum += $order_goods_detail['goods_num'];
          $class_total_fee +=  $va['total_amount'];
          
          if($va['yajin'] != "0.00") {
            $class_total_qk += $va['total_amount']-$va['yajin'];
            $class_total_yajin += $va['yajin'];
          }else{
            $class_total_qk +=0;
            $class_total_yajin += $va['total_amount'];
          }
        }
        
        $order_count_detail[$key] = array(
          'class_id' => $key,
          'classname' => $classname,
          'classnum' => $classnum,
          'class_total_fee' => $class_total_fee,
          'class_total_yajin' => $class_total_yajin,
          'class_total_qk' => $class_total_qk,
          'class_total_hk' => $class_total_hk,
          'store_id' => $store_id,
        );
        $total_fee += $class_total_fee;
        $total_num += $classnum;
        $total_yajin += $class_total_yajin;
        $total_qk += $class_total_qk;
      }

      $total_list = array(
          'total_num' => $total_num,
          'total_fee' => $total_fee,
          'total_yajin' => $total_yajin,
          'total_qk' => $total_qk,
        );
      $this->assign('total_list',$total_list);
      $this->assign('order_count_detail',$order_count_detail);
      $this->assign('storeinfo',$storeinfo);
      $this->assign('store_id',$store_id);
      $this->assign('nickname',$nickname);
      $this->display();
    }
    public function seller(){
       $timegap=$_REQUEST['timegap'];
        $timegap1=$_REQUEST['timegap1'];
      if($timegap){
        $begin =strtotime($timegap);
        $end = strtotime($timegap1)+86399;
      }else{
        $begin1 = date('Y-m-d');//30天前
        $begin = strtotime($begin1);
        $end =time();
      }
      $user=session();
      $nickname=$user['admin']['user_name'];
      if($nickname==''){
        $nickname=$user['user']['nickname'];
      }
      $store_id=$_GET['store_id'];
      $class_id=$_GET['class_id'];
      $class = M('goods_category')->field('name')->where("level=3 and id=$class_id")->find();
      $classname=$class['name'];

      $seller=M('seller')->field('user_id,group_id')->where("store_id=$store_id and is_admin=0")->order('group_id desc')->select();
       
      foreach($seller as $key => $val){
        $tuiguangid=$val['user_id'];
          $user_name=M('users')->field('nickname')->where("user_id=$tuiguangid")->find();
          $name=$user_name['nickname'];
          $group_id=$val['group_id'];
          
          $sql="select b.goods_num from ty_order a ,ty_order_goods b, ty_goods c where a.order_id= b.order_id and b.goods_id=c.goods_id and c.cat_id3=$class_id and a.order_status in (1,2,4,6) and a.store_id=$store_id and a.tuiguangid=$tuiguangid and a.add_time >=$begin and a.add_time <= $end";
          $arr=M()->query($sql);
          
           $classnum = 0;
        $class_total_fee = 0;
        $class_total_yajin = 0;
        $class_total_qk = 0;
          foreach($arr as $v){
            $classnum+=$v['goods_num'];
            $class_total_fee +=  $v['total_amount'];
          
          if($v['yajin'] != "0.00") {
            $class_total_qk += $v['total_amount']-$v['yajin'];
            $class_total_yajin += $v['yajin'];
          }else{
            $class_total_qk +=0;
            $class_total_yajin += $v['total_amount'];
          }
          }
           $order_count_detail[$key] = array(
          'class_id' => $key,
          'classname' => $classname,
          'classnum' => $classnum,
          'class_total_fee' => $class_total_fee,
          'class_total_yajin' => $class_total_yajin,
          'class_total_qk' => $class_total_qk,
          'class_total_hk' => $class_total_hk,
          'store_id' => $store_id,
        );
        $total_fee += $class_total_fee;
        $total_num += $classnum;
        $total_yajin += $class_total_yajin;
        $total_qk += $class_total_qk;
      }
      $total_list = array(
          'total_num' => $total_num,
          'total_fee' => $total_fee,
          'total_yajin' => $total_yajin,
          'total_qk' => $total_qk,
        );
      $this->assign('total_list',$total_list);
      $this->assign('order_count_detail',$order_count_detail);  
       $this->assign('nickname',$nickname);
      $this->display();
    }
    public function xiaji(){
       $timegap=$_REQUEST['timegap'];
        $timegap1=$_REQUEST['timegap1'];
      if($timegap){
        $begin =strtotime($timegap);
        $end = strtotime($timegap1)+86399;
      }else{
        $begin1 = date('Y-m-d');//30天前
        $begin = strtotime($begin1);
        $end =time();
      }
      $user=session();
      $nickname=$user['admin']['user_name'];
      if($nickname==''){
        $nickname=$user['user']['nickname'];
      }
      $user_id=$_GET['user_id'];

      $class = M('goods_category')->field('id,name')->where("level=3")->select();
      $class_id = array();
      $class_name = array();
      foreach ($class as $key => $v) {
        $class_id[] = $v['id'];
        $class_name[$v['id']] = $v['name'];
      }
      $class_id = implode(',', $class_id);
      $class_goods = M('goods')->field('goods_id,cat_id3,goods_name')->where("cat_id3 in ($class_id)")->select();
    
      $class_goods_f = array();
      //获取分类的商品id
      foreach($class_goods as $v)
      {
        $class_goods_f[$v['cat_id3']][] = $v['goods_id'];
      }
      //根据分类的商品id查询总金额欠款等
      $order_detail = M('order')->field('user_id,consignee,tuiguangid,doctor_id,total_amount,yajin,order_id,pay_code,add_time')
      ->where("add_time >=$begin and add_time <=$end  and order_status in(1,2,4,6) and tuiguangid=$user_id")
      ->select();
      $order_count_detail = array();
      $user_name=M('users')->field('nickname')->where("user_id=$user_id")->find();
      $username=$user_name['nickname'];
      foreach ($class_goods_f as $key => $v) {
        $vn = implode(',', $v);
        $classnum = 0;
        $class_total_fee = 0;
        $class_total_yajin = 0;
        $class_total_qk = 0;
        foreach ($order_detail as $ke => $va) {
          $order_goods_detail = M('order_goods')->field('goods_id,goods_num,goods_name')
          ->where("order_id = ".$va['order_id']." and goods_id in($vn)")->find();
          $classname = $class_name[$key];
          if (!$order_goods_detail) {
            continue;
          }
          
          $classnum += $order_goods_detail['goods_num'];
          $class_total_fee +=  $va['total_amount'];
          
          if($va['yajin'] != "0.00") {
            $class_total_qk += $va['total_amount']-$va['yajin'];
            $class_total_yajin += $va['yajin'];
          }else{
            $class_total_qk +=0;
            $class_total_yajin += $va['total_amount'];
          }
          $class_total_hk .= "[".$va['pay_code']."]";

        }
        
        $order_count_detail[$key] = array(
          'username'=>$username,
          'classname' => $classname,
          'classnum' => $classnum,
          'class_total_fee' => $class_total_fee,
          'class_total_yajin' => $class_total_yajin,
          'class_total_qk' => $class_total_qk,
          'class_total_hk' => $class_total_hk,
        );
        $total_fee += $class_total_fee;
        $total_num += $classnum;
        $total_yajin += $class_total_yajin;
        $total_qk += $class_total_qk;
      }

      $total_list = array(
          'total_num' => $total_num,
          'total_fee' => $total_fee,
          'total_yajin' => $total_yajin,
          'total_qk' => $total_qk,
        );
      $this->assign('total_list',$total_list);
      $this->assign('order_count_detail',$order_count_detail);
      $this->assign('storeinfo',$storeinfo);
      $this->assign('store_id',$store_id);
      $this->assign('nickname',$nickname);
      $this->display();
    }
    public function user_list(){
      $user=session();
      $nickname=$user['admin']['user_name'];
      if($nickname==''){
        $nickname=$user['user']['nickname'];
      }
      $b=$user['user'];
      
      if($b&&$b['seller_id']>'0'){
        $group_id=$b['group_id'];
        $user_id=$b['user_id'];
        $roleid=$b['roleid'];
        $store_id=$b['seller_id'];
        if($group_id=='6'or $group_id='9'or $group_id='10'){
         
          $where="seller_id=$store_id and roleid=$roleid and group_id='0'";

        }else{
          $where="seller_id=$store_id and roleid=$roleid and tuixiao_id=$user_id and group_id='0'";
        }
        $model = M('users');
        $count = $model->where($where)->count();
        $Page  = new Page($count,10);
       
        $user1=M('users')->where($where)->order('user_id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
        foreach($user1 as &$v){
          $store_id=$v['seller_id'];
          $tuixiao_id=$v['tuixiao_id'];
          $store_name=M('store')->field('store_name')->where("store_id=$store_id")->find();
          $tuixiao_name=M('users')->field('nickname')->where("user_id=$tuixiao_id")->find();
          $v['store_name']=$store_name['store_name'];
          $v['tuixiao_name']=$tuixiao_name['nickname'];
        }
         $show = $Page->show();
      }else{
          $roleid=$user['admin']['role_id'];
          if($roleid==''){
            $roleid=$user['user']['roleid'];
          }
          $model = M('users');
          $count = $model->where("tuixiao_id >'0' and roleid=$roleid")->count();
          $Page  = new Page($count,10);
       $user1=M('users')->where("tuixiao_id >'0' and roleid=$roleid")->order('user_id DESC')->limit($Page->firstRow.','.$Page->listRows)->select();
       foreach($user1 as &$v){
          
          $store_id=$v['seller_id'];
          $tuixiao_id=$v['tuixiao_id'];
          $store_name=M('store')->field('store_name')->where("store_id=$store_id")->find();
          $tuixiao_name=M('users')->field('nickname')->where("user_id=$tuixiao_id")->find();
          $v['store_name']=$store_name['store_name'];
          $v['tuixiao_name']=$tuixiao_name['nickname'];
        }
         $show = $Page->show();
      }
      $this->assign('page',$show);// 赋值分页输出
      $this->assign('user1',$user1);
      $this->assign('nickname',$nickname);
      $this->display();
    }
    public function detail(){
      $user=session();
      $nickname=$user['admin']['user_name'];
      if($nickname==''){
        $nickname=$user['user']['nickname'];
      }
      $user_id=$_GET['user_id'];
      $user=M('users')->where("user_id=$user_id")->find();
      $tuixiao_id=$user['tuixiao_id'];
      $tuixiao=M('users')->where("user_id=$tuixiao_id")->find();
      $tx=M('user_tx')->where("user_id=$user_id")->select();
      $this->assign('tx',$tx);
      $this->assign('user',$user);
      $this->assign('tuixiao',$tuixiao);
      $this->assign('nickname',$nickname);
      $this->display();
    }
}

